package net.cn_su.sharpeyes.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.cn_su.sharpeyes.R;
import net.cn_su.sharpeyes.baseadapter.AdapterCallback;
import net.cn_su.sharpeyes.baseadapter.CommonAdapter;
import net.cn_su.sharpeyes.baseadapter.ViewHolder;
import net.cn_su.sharpeyes.beans.Organization;

import java.util.List;

/**
 * 切换乡镇
 */
public class OrgAdapter extends CommonAdapter<Organization> {


    AdapterCallback mCallback;

    public OrgAdapter(Context context, List<Organization> mDatas, int itemLayoutId, AdapterCallback adapterCallback) {
        super(context, mDatas, itemLayoutId, adapterCallback);
        mCallback = adapterCallback;
    }


    @Override
    public void convert(final ViewHolder holder, final Organization item, int positon) {

        TextView tv_name = holder.getView(R.id.textView);


        //镇
        if (item.getOrg_type() == 0) {


            holder.setTextViewText(R.id.textView_count, "共" + item.getChild_size() + "个");


            holder.setTextViewText(R.id.textView, item.getName())
                    .setBackgroundColor(R.id.ll_bg, mContext.getResources().getColor(R.color.gray))
                    .setViewVisibility(R.id.textView_count, View.VISIBLE)
                    .setViewVisibility(R.id.ll_confirm, View.GONE)
            ;

        } else {

            holder.setTextViewText(R.id.textView, item.getName())
                    .setBackgroundColor(R.id.ll_bg, mContext.getResources().getColor(R.color.bg_color))
                    .setViewVisibility(R.id.textView_count, View.GONE)
                    .setViewVisibility(R.id.ll_confirm, View.VISIBLE)
            ;

            TextView tv_confirm = holder.getView(R.id.tv_confirm);
            LinearLayout ll_confirm = holder.getView(R.id.ll_confirm);

            switch (item.getStatus()) {
                case -1:
                    //没有申请过
                    tv_confirm.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.btn_confirm));
                    tv_confirm.setText("申请加入");
                    //申请
                    ll_confirm.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                           adapterCallback.adapterInfotoActiity(item, 2);
                        }
                    });

                    break;
                case 0:
                    tv_confirm.setBackgroundColor(mContext.getResources().getColor(R.color.bg_color));
                    tv_confirm.setText("申请中");
                    break;
                case 1:
                    tv_confirm.setBackgroundColor(mContext.getResources().getColor(R.color.bg_color));
                    tv_confirm.setText("已申请");
                    break;
                case 2:
                    //未通过
                    tv_confirm.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.btn_confirm));
                    tv_confirm.setText("重新申请");
                    //申请
                    ll_confirm.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                           adapterCallback.adapterInfotoActiity(item, 2);
                        }
                    });
                    break;
            }


        }


    }


}
